package com.lm.survey.model;

import java.util.ArrayList;
import java.util.*;
import java.util.List;
import java.util.Map;

public class QuestionGroup {
	
	
	private int id;
	private int questonnareId;
	private String name;
	private String relationValue;
	private String description;
	int seq = 0;
	
	Map<Integer,QuestionItem> maps   = new HashMap<Integer,QuestionItem>();
	public QuestionItem getQuestionItem(int itemId){
	    return maps.get(itemId);
	}
	public List<QuestionItem> getItems() {
	    TreeSet<QuestionItem> set = new TreeSet<QuestionItem>(new ItemComparator());
	    set.addAll(maps.values());
	    return new ArrayList(set);
//        return new ArrayList(maps.values());
    }
    public void setItems(List<QuestionItem> items) {
        QuestionItem item = null;
        for(int i=0;i<items.size();i++){
            item = items.get(i);
            maps.put(item.getId(), item);
        }
       
    }
    public int getSeq() {
		return seq;
	}
	public void setSeq(int seq) {
		this.seq = seq;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public int getQuestonnareId() {
		return questonnareId;
	}
	public void setQuestonnareId(int questonnareId) {
		this.questonnareId = questonnareId;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getRelationValue() {
		return relationValue;
	}
	public void setRelationValue(String relationValue) {
		this.relationValue = relationValue;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	
	class  ItemComparator implements Comparator{	    
	    public int compare(Object o1, Object o2){
	        QuestionItem i1 = (QuestionItem)o1;
	        QuestionItem i2 = (QuestionItem)o2;
	        return i1.compare(i2);
	        
	    }
	}
	
}
